home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / CPX / GENERAL.TC / KEYBOARD.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  4.3 KB  |  196 lines

  1. /* KEYBOARD.C
  2.  *==========================================================================
  3.  * DATE:    March 21, 1990
  4.  * DESCRIPTION: Keyboard Response and Repeat Routines
  5.  */
  6.  
  7.  
  8.  /* INCLUDE FILES
  9.  *==========================================================================
  10.  */ 
  11. #include <sys\gemskel.h>
  12. #include <tos.h>
  13.  
  14. #include "country.h"
  15.  
  16. #include "general.h"
  17. #include "gen2.h"
  18.  
  19.  
  20.  
  21. /* DEFINES
  22.  *==========================================================================
  23.  */
  24. #define VERTICAL    0
  25. #define HORIZONTAL    1
  26.  
  27. /* Keyboard response and repeat rate max and min */
  28. #define KEYMAX 50
  29. #define KEYMIN 1
  30.  
  31.  
  32. /* PROTOTYPES
  33.  *==========================================================================
  34.  */
  35. void    Set_Kbrate( void );
  36. void    Get_Kbrate( void );
  37. void    Kbrate_Update( void );
  38. void    Kb_itoa( int n, char *s );
  39.  
  40. void    KResponse( void );
  41. void    KRepeat( void );
  42.  
  43.  
  44. /* EXTERNALS
  45.  *==========================================================================
  46.  */
  47.  
  48.  
  49. /* GLOBALS 
  50.  *==========================================================================
  51.  */
  52. char Rep_Text[5];
  53. char Resp_Text[5];
  54.  
  55. /* FUNCTIONS
  56.  *==========================================================================
  57.  */
  58.  
  59.  
  60.  
  61. /* Set_Kbrate()
  62.  *==========================================================================
  63.  * Set Keyboard Repeat and Response Rate
  64.  */ 
  65. void
  66. Set_Kbrate( void )
  67. {
  68.    Kbrate( cur_value.response, cur_value.repeat );
  69. }
  70.  
  71.  
  72.  
  73. /* Get_Kbrate()
  74.  *==========================================================================
  75.  * Get keyboard Repeat and Response Rate
  76.  */
  77. void
  78. Get_Kbrate( void )
  79. {
  80.     int cur_rate;
  81.     
  82.     cur_rate = Kbrate( -1, -1);
  83.     cur_value.repeat   = cur_rate & 0xFF;
  84.     cur_value.response = (cur_rate >> 8) & 0xFF;
  85.  
  86.     if( cur_value.repeat < KEYMIN )
  87.            cur_value.repeat = KEYMIN;
  88.            
  89.     if( cur_value.response < KEYMIN )
  90.            cur_value.response = KEYMIN;
  91.     
  92.     if( cur_value.repeat > KEYMAX )
  93.          cur_value.repeat = KEYMAX;
  94.          
  95.     if( cur_value.response > KEYMAX )
  96.          cur_value.response = KEYMAX;
  97.  
  98.     Set_Kbrate();         
  99. }
  100.  
  101.  
  102.  
  103. void
  104. Kbrate_Update( void )
  105. {
  106.    OBJECT *tree = ( OBJECT *)rs_trindex[ GENERAL ];
  107.    
  108.    (*xcpb->Sl_size)( tree, RESPBASE, KRESPONS, KEYMAX, 20, HORIZONTAL, 0 );
  109.    (*xcpb->Sl_size)( tree, REPTBASE, KREPEAT, KEYMAX, 20, HORIZONTAL, 0 );
  110.    
  111.    (*xcpb->Sl_x)( tree, RESPBASE, KRESPONS, cur_value.response,
  112.                  KEYMIN, KEYMAX, KResponse ); 
  113.    (*xcpb->Sl_x)( tree, REPTBASE, KREPEAT, cur_value.repeat,
  114.                  KEYMIN, KEYMAX, KRepeat );
  115. }
  116.  
  117.  
  118.  
  119. /* KRepeat()
  120.  *==========================================================================
  121.  * Repeat Rate Slider Update Code
  122.  */
  123. void
  124. KRepeat( void )
  125. {
  126.     OBJECT *tree = ( OBJECT *)rs_trindex[ GENERAL ];
  127.     
  128.     Kb_itoa( cur_value.repeat, TedText( KREPEAT ));
  129.     Objc_draw( tree, KREPEAT, 0,NULL);
  130. }
  131.  
  132.  
  133.  
  134. /* KResponse()
  135.  *==========================================================================
  136.  * Response Rate Slider Update Code
  137.  */
  138. void
  139. KResponse( void )
  140. {
  141.     OBJECT *tree = ( OBJECT *)rs_trindex[ GENERAL ];
  142.     
  143.     Kb_itoa( cur_value.response, TedText( KRESPONS ));
  144.     Objc_draw( tree, KRESPONS, 0,NULL);
  145. }
  146.  
  147.  
  148.  
  149.  
  150. /* Kb_itoa()
  151.  *==========================================================================
  152.  * integer to ascii conversion based upon 20ms ticks
  153.  */
  154. void
  155. Kb_itoa( int n, char *s )
  156. {
  157.     n *= 20;                    /* 20ms ticks */
  158.     *s++ = n / 1000 + '0';
  159.     *s++ = '.';
  160.     n %= 1000;
  161.     *s++ = n / 100 + '0';
  162.     n %= 100;
  163.     *s++ = n / 10 + '0';
  164.     *s = '\0';
  165. }
  166.  
  167. void
  168. Kbrate_Redraw( void )
  169. {
  170.    OBJECT *tree = ( OBJECT *)rs_trindex[ GENERAL ];
  171.    int old_repeat   = cur_value.repeat;
  172.    int old_response = cur_value.response;
  173.    
  174.    Get_Kbrate();
  175.  
  176.    if( old_repeat != cur_value.repeat )
  177.    {
  178.         (*xcpb->Sl_x)( tree, REPTBASE, KREPEAT, cur_value.repeat,
  179.                       KEYMIN, KEYMAX, NULLFUNC );
  180.         Kb_itoa( cur_value.repeat, Rep_Text );
  181.         TedText( KREPEAT ) = Rep_Text;
  182.        do_redraw( tree, REPTBASE );
  183.    }    
  184.        
  185.    if( old_response != cur_value.response )
  186.    {
  187.         (*xcpb->Sl_x)( tree, RESPBASE, KRESPONS, cur_value.response,
  188.                       KEYMIN, KEYMAX, NULLFUNC ); 
  189.     Kb_itoa( cur_value.response, Resp_Text );
  190.     TedText( KRESPONS ) = Resp_Text;
  191.       do_redraw( tree, RESPBASE );
  192.    }    
  193. }
  194.  
  195.  
  196.